//
//  QJMineEditBankVC.m
//  QuanJieShopProject
//
//  Created by 刘中义 on 2018/2/27.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "QJMineEditBankVC.h"
@interface QJMineEditBankVC ()

@end

@implementation QJMineEditBankVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    if (self.model) {
        self.title = @"编辑银行卡";
        self.bankNumberTF.text = [NSString stringWithoutNilFormart:self.model.card_num];
        self.bankPeopleTF.text = [NSString stringWithoutNilFormart:self.model.card_name];
        self.bankCardTF.text = [NSString stringWithoutNilFormart:self.model.id_card];
        self.bankPhoneTF.text = [NSString stringWithoutNilFormart:self.model.mobile];
        self.bankNameTF.text = [NSString stringWithoutNilFormart:self.model.bank_name];
        [self.addBtn setTitle:@"确 定" forState:UIControlStateNormal];
    }else{
        self.title = @"添加银行卡";
    }
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //控件不被导航栏遮挡
    self.navigationController.navigationBar.translucent = NO;
}
- (IBAction)addBankBtnClickAction:(UIButton *)sender {
    if (![self.bankPhoneTF.text validateMobilePhone]) {
        [MBPHUD showAlertWithTitle:@"请检查输入手机号格式!"];
    }else if (![self.bankCardTF.text validateIDCard]){
        [MBPHUD showAlertWithTitle:@"请检查身份证号格式!"];
    }else if (![self.bankNumberTF.text validateBandCard]){
        [MBPHUD showAlertWithTitle:@"请检查银行卡号格式!"];
    }else if (self.bankPeopleTF.text.length > 0 && self.bankNameTF.text.length > 0){
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        [dict setObject:self.bankNumberTF.text forKey:@"cardNum"];
        [dict setObject:self.bankPeopleTF.text forKey:@"cardName"];
        [dict setObject:self.bankCardTF.text forKey:@"idCard"];
        [dict setObject:self.bankPhoneTF.text forKey:@"mobile"];
        [dict setObject:self.bankNameTF.text forKey:@"bankName"];
        if (self.model) {
            [dict setObject:self.model.id forKey:@"id"];
            [WWNetRequest fetchEditBankCardWithParameters:dict success:^(id response) {
                if (response) {
                    [MBPHUD showAlertWithTitle:@"银行卡信息提交成功!"];
                    KPopViewControllerAction;
                }
            } failure:^(NSDictionary *error) {
                
            }];
        }else{
            [WWNetRequest fetchAddBankCardWithParameters:dict success:^(id response) {
                if (response) {
                    [MBPHUD showAlertWithTitle:@"银行卡信息提交成功!"];
                    KPopViewControllerAction;
                }
            } failure:^(NSDictionary *error) {
                
            }];
        }
        ;
    }else{
        [MBPHUD showAlertWithTitle:@"请输入完整的信息!"];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
